Skip to content

coverage: an undeclared region is a refusal, not a skipped gate (C-113) - #335

Merged
Polichinel merged 3 commits into
developmentfrom
fix/coverage-region-must-be-declared-113
Nov 18, 2026
Merged

Polichinel merged 3 commits into
developmentfrom
fix/coverage-region-must-be-declared-113

Conversation

@Polichinel

@Polichinel Polichinel commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Closes the Tier-2 half of C-113 and the silent half nobody had registered separately.

The defect

expected_for(None) returned None; excluded_for(None) returned frozenset() — the same values a region that is declared but not pinned returns. So a launch config omitting region shipped a delivery whose cell curation and completeness check had both done nothing, and it read as a supported configuration.

One of those two states is supported: africa_me_legacy is deliberately unpinned, because with 5 pure-ocean cells "complete" is ambiguous. The other is ADR-003 inference by omission.

Where the fix went, and why not where it looks like it belongs

Into contract/launch_config.py, as assert_region_declared — a sibling of assert_contract_mode and assert_frame_native_historical, called from _read_forecast_data in both managers before any store call. region was the only product-defining launch axis read through a bare .get(); the other two already had declared assertions. This is that module's whole job.

delivery/coverage.py holds the same rule at the invariant, for every other caller (tests, scripts/build_gaul_lookup.py, a future third partner): expected_for/excluded_for raise RegionNotDeclaredError on an undeclared region and still return None/empty for a declared-but-unpinned one.

RegionNotDeclaredError is not a CoverageError subclass, deliberately — nothing was delivered wrongly, the question could not be asked, and a caller catching CoverageError to report a coverage failure must not catch this and mislabel it.

The silent half, fixed with it

The count gate logged its skip. The exclusion gate did not. So a delivery curated by nothing left only half its evidence in the run log — which is why C-113's own Tier rationale ("the count-gate logs a warning before skipping, so the evidence does reach the run log") was true of one gate and not the pair.

Both gates now report their own skip inside the invariant: assert_complete_coverage accepts expected_count=None, assert_no_excluded_cells an empty manifest, each logging a WARNING naming the leg.

That is also what let this land. My first attempt put the reporting in the managers and tripped test_doc_accuracy's 300-line manager ratchet at 319 lines. The ratchet was right, and C-40(a) says why: logic that can be called with declared arguments belongs where it can be tested without a manager, an Appwrite environment or a views-models path manager. Moving it inward made the managers shorter than before and the skips provable by caplog with no framework at all.

The entry's warning was the load-bearing part

C-113 said: "A guard written the other way round, refusing any region absent from EXPECTED_CELLS, would make africa_me_legacy unlaunchable."

The uncommitted falsification stub from the same day prescribed exactly that — a refusal naming land_gaul for any unpinned region. It is not adopted; test_a_declared_region_passes_whether_or_not_it_is_pinned pins the opposite. The stub's finding was right and its remedy was wrong on one of its two points. It has been moved out of tests/ to the session scratchpad rather than deleted.

Also

Corrects coverage.py's header pointer to unfao/extraction.py, deleted in #151 — one of the two stale docstring pointers C-107 names. The other (observed_range.py:6) is untouched and still recorded.

Noted, not fixed: coverage.py's existing raises do not log before raising (ADR-008). I added the module logger for the two skip warnings and left the raises alone rather than widen this change.

Verification

  • Full suite 545 passed, 3 skipped, 41 xfailed (was 529 — 16 new tests).
  • ruff check clean.
  • test_register_integrity.py 12 passed; C-113 moved to Resolved, Cluster O records its first discharge, header 39 open / 85 resolved.
  • Both skip paths asserted on the WARNING record rather than the return value, because returning None is what the old silent version did too.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ANY1CCy9Xo7zjMY4XJ69v9


Update 2026-11-18 — three claims above were wrong, and a guard audit found four more holes

Everything above describes the first commit. /code-review and an independent /falsify guard run on this branch both found it closed the smaller leg and claimed the pair. Second commit: 4604ab2.

1. "Both gates now report their own skip" was false on the forecast leg

Forecast coverage is not asserted in the managers at all. It is asserted inside contract/wire/source_selection.py's TargetLease.load(), where the frame exists — and there both calls sat behind if self.excluded_gids: and if self.expected_cells is not None:. For a region pinning neither, both conditions were false, so every forecast target loaded with both gates skipped and nothing at all in the run log. The managers' _check_coverage, which the first commit fixed, covers only the historical leg.

Both ifs are gone. The lease calls each gate unconditionally, which is the only form that lets the invariant own its skip report.

2. A misspelled region still disabled both gates

assert_region_declared accepted any non-empty string. So region: "lnd_gaul" passed the launch refusal, missed both dictionary lookups, and skipped both gates — while reporting itself as the deliberately-unpinned configuration. Measured: expected_for("lnd_gaul") -> None, excluded_for("lnd_gaul") -> frozenset(), and a two-cell delivery accepted. One mistyped letter undid exactly what declaring a region is for.

C-113 anticipated the wrong guard here — "refusing any region absent from EXPECTED_CELLS", which would ground africa_me_legacy — and this is the right one: KNOWN_REGIONS, a declared set of the regions this delivery recognises, kept separate from whether a known region's cell count has been verified. africa_me_legacy is known, still unpinned, still launches, still logs a skipped count-gate. An unrecognised name raises UnknownRegionError at the invariant and LaunchConfigError at launch, each naming the known set and both repair paths.

Correction to the section above: test_a_declared_region_passes_whether_or_not_it_is_pinned asserted that region: "not_pinned_anywhere" launches. That generalised correctly from africa_me_legacy to the wrong conclusion. It is renamed and narrowed; expected_for("does_not_exist") is None is likewise rewritten. Both pinned the defect.

3. "before any store call" was imprecise

The historical leg runs first, so the refusal is not the run's first I/O. Both managers' docstrings now say contract-store call, which is what the sentence was about.

4. The guard audit: 38 mutations, 31 caught, 7 survived

Run independently, with no access to the commit message or the register entry. Every mutation against delivery/coverage.py was caught — the invariant layer is strongly guarded. All seven survivors were at the call sites this change created an obligation for, or in the declaration the invariant is told to trust. Each left the full suite green:

Mutation Why it mattered Closed by
Restore if excluded: / if expected is not None: in both managers reopens C-113's silence on the historical leg ast scan: each gate called once in _check_coverage, neither enclosed by an If
Add "atlantis" to KNOWN_REGIONS the declaration was checked only in the direction pinned ⊆ known cross-check against views-datafactory's src/datafactory_query/regions.py, read with ast, skipped when no sibling checkout
Delete both logger.error in assert_region_declared breaks ADR-008 unnoticed two entries in test_env_declaration.py::_REFUSALS — the mechanism already existed and the validator had not been added to it
Delete the manager call site of assert_region_declared the source scan read unfao.py only, and listed two of three assertions parametrised over both partners, all three assertions
Swap the two gate calls both managers and the lease say the order is load-bearing, in comments only call-order assertion on the forecast leg, line-order assertion in both managers
Blind the exclusion gate (leaked = []) one new test asserted something untrue of itself — its comment claimed the exclusion gate fires where drop_units had already removed the cell; the CoverageError it caught came from the count gate comment corrected, assertion now names the count gate, and a separate test states what the exclusion gate is for on that leg: a post-condition on the curation it follows

The pattern is worth keeping: moving skip-reporting out of the two shells and into the invariant was sound and is well guarded. What went unguarded was the shells' remaining obligation to call it — an obligation this change itself created.

Register

  • C-113's resolution amended with all of the above. Its prose was the thing that was wrong, which no Location check would have caught (cross-ref added to C-109).
  • New C-124 — the §6 draws gate catches Exception around np.asarray and reports every failure as "malformed input, not a collapsed forecast". MemoryError is an Exception, and this path has two measured OOMs behind it (C-32, C-101), so an out-of-memory failure sends the reader to the producer. One line and one test to fix; registered, not fixed here, so delivery/draws.py stays out of this diff.
  • The review's fourth finding (the credential tripwire naming the wrong key) is already open as C-115 — no new entry.
  • C-117's title date has passed; C-123's cited stub path no longer resolves because the session scratchpad was cleared. Both noted in place.

Verification, re-measured

  • Full suite 565 passed, 3 skipped, 41 xfailed — up from 545, twenty new tests. Supersedes the "545" above.
  • ruff check . clean.
  • Run in a poetry install environment matching poetry.lock (views-frames 3.0.0, views-pipeline-core 3.4.0), so test_locked_environment passes rather than being skipped around.
  • Guard-audit tree state verified clean: every mutation reverted, git status back to the expected ten files.

Polichinel and others added 2 commits November 12, 2026 22:01
…(C-113)

`expected_for(None)` returned None and `excluded_for(None)` returned an empty
set — the same values a region that is DECLARED but not pinned returns. So a
launch config omitting `region` shipped a delivery whose cell curation and
completeness check had both done nothing, reported as a supported
configuration. One of the two is supported: `africa_me_legacy` is deliberately
unpinned because "complete" is ambiguous there. The other is ADR-003 inference
by omission.

The refusal goes where this repo already keeps launch declarations, not into a
new guard beside the gates: `launch_config.assert_region_declared`, sibling of
`assert_contract_mode` and `assert_frame_native_historical`, called from
`_read_forecast_data` before any store call. `delivery/coverage.py` holds the
same rule at the invariant for every other caller — `RegionNotDeclaredError`
on undeclared, None/empty still for declared-but-unpinned.

`RegionNotDeclaredError` is not a `CoverageError` subclass, deliberately.
Nothing was delivered wrongly; the question could not be asked, and a caller
catching CoverageError must not mislabel it as a coverage failure.

A second, silent half fixed with it: the count gate logged its skip and the
exclusion gate did not, so an uncurated delivery left half its evidence in the
run log. Both gates now report their own skip INSIDE the invariant —
`assert_complete_coverage` accepts None, `assert_no_excluded_cells` accepts an
empty manifest. That is also what let this land: putting the reporting in the
managers tripped the 300-line ratchet at 319, and the ratchet was right (C-40
(a)). Both skips are now proven by caplog with no framework at all, and the
managers got shorter rather than longer.

The entry's warning was the load-bearing part — "a guard refusing any region
absent from EXPECTED_CELLS would make africa_me_legacy unlaunchable". The
uncommitted falsification stub prescribed exactly that; it is not adopted, and
a test now pins the opposite.

Also corrects coverage.py's header pointer to a module deleted in #151 — one
of the two stale docstring pointers C-107 names.

16 new tests, suite 529 -> 545 passed. C-113 moves to Resolved; Cluster O
records its first discharge.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ANY1CCy9Xo7zjMY4XJ69v9
… misspelling

Review and an independent guard audit on this branch both found that the first
commit closed the smaller leg and claimed the pair.

The forecast leg. Coverage is not asserted in the managers for forecasts: it is
asserted in `TargetLease.load`, where the frame exists. Both calls there were
wrapped in `if self.excluded_gids:` / `if self.expected_cells is not None:`, so a
region that pins neither ran every target with both gates skipped and nothing in
the run log. That is the silence C-113 is about, on the leg that does most of the
checking. Both `if`s are gone; each gate reports its own skip.

A misspelling. `assert_region_declared` accepted any non-empty string, so
`region: "lnd_gaul"` passed it, missed both lookups, and skipped both gates while
reporting itself as the deliberately-unpinned configuration. KNOWN_REGIONS now
declares the regions this delivery recognises, separately from whether a region's
cell count is pinned: `africa_me_legacy` is known and still unpinned, and still
launches. An unrecognised name raises UnknownRegionError at the invariant and
LaunchConfigError at launch, each naming the known set and both repair paths.

Two tests from the first commit pinned the old behaviour and are rewritten.

The guard audit applied 38 mutations and 7 survived, all at the call sites this
change created an obligation for, or in the declaration the invariant trusts:
restoring the caller-side `if`s in both managers, adding a fictional region to
KNOWN_REGIONS, deleting both ADR-008 `logger.error` calls, deleting the manager
call site, and swapping the load-bearing gate order all left the suite green —
and one new test asserted something untrue of itself (it claimed the exclusion
gate fired where `drop_units` had already removed the cell). All seven are closed:
an ast scan of both managers' `_check_coverage`, a cross-check of KNOWN_REGIONS
against views-datafactory's own regions.py, two entries in
test_env_declaration's _REFUSALS, a parametrised manager source scan, call-order
and line-order assertions, and an honest exclusion-gate test.

Register: C-113's resolution amended with both findings and the audit. New
C-124 — the §6 draws gate catches `Exception` and reports a MemoryError as
malformed producer input. Registered, not fixed here, so draws.py stays out of
this diff. C-117 and C-123 location notes corrected.

565 passed, 3 skipped, 41 xfailed; ruff clean — measured in the poetry.lock env.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ANY1CCy9Xo7zjMY4XJ69v9
The entry said what to do and why it was not done on this branch; it did not
say where the work now lives. A register entry with no home for its remedy is
how C-40's standing-work half became hard to find.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ANY1CCy9Xo7zjMY4XJ69v9
@Polichinel
Polichinel merged commit 11b41da into development Nov 18, 2026
4 checks passed
@Polichinel
Polichinel deleted the fix/coverage-region-must-be-declared-113 branch November 18, 2026 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant